﻿using System;
using System.Collections.Generic;
using System.Data;
using ContractManager.Common.Class;
using ContractManager.Entity;
using Speed.Data;

namespace ContractManager.BLL.Business
{
    public static class ClsTenderDocuments
    {
        public static List<TenderDocuments> SelectAll()
        {
            using (var db = Sys.NewDb())
            {
                return Data.Base.TenderDocuments.Select(db);
            }
            
        }

        public static DataTable GetAll(int formNo, int voucherCate, DateTime fromDate, DateTime toDate)
        {
            using (var db = Sys.NewDb())
            {
                string commandText = String.Format("EXEC dbo.usp_TenderDocuments_GetAll {0},{1},{2},{3},'{4}','{5}'",
                                            ClsVariable.AsSysMyCoYearId,
                                            formNo,
                                            voucherCate,
                                            ClsVariable.EmployeeId,
                                            fromDate.ToString("dd/MMM/yyyy"),
                                            toDate.ToString("dd/MMM/yyyy"));
                return db.ExecuteDataTable(commandText);
            }

        }

        public static void Insert(TenderDocuments capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Insert<TenderDocuments>(capital, EnumSaveMode.Requery);
            }
            
        }

        public static void Update(TenderDocuments capital)
        {
            using (var db = Sys.NewDb())
            {
                db.Update<TenderDocuments>(capital);
            }
            
        }

        public static TenderDocuments SelectByPk(Int32 docId)
        {
            using (var db = Sys.NewDb())
            {
                return db.SelectSingle<TenderDocuments>(string.Format("TenDocId={0}", docId));
            }
            
        }

        public static int DeleteByPk(Int32 docId)
        {
            using (var db = Sys.NewDb())
            {
                return db.Delete<TenderDocuments>(string.Format("TenDocId={0}", docId));
            }
           
        }
    }
}